# //python
import unittest
from unittest.mock import patch
from sqjz import sqjz_signal

class TestSqjqFunction(unittest.TestCase):
    def setUp(self):
        self.C = [6, 5, 4, 3, 2, 1, 0, -1, -2, -3]

    @patch('sqjz.REF')
    @patch('sqjz.REFXV')
    @patch('sqjz.COUNT')
    @patch('sqjz.BARSLASTCOUNT')
    @patch('sqjz.MOD')
    def test_sqjq_all_buy_signals(self, mock_mod, mock_barslastcount, mock_count, mock_refxv, mock_ref):
        mock_ref.side_effect = lambda data, periods: [d - periods for d in data]
        mock_refxv.side_effect = lambda count, x: count
        mock_count.return_value = 9
        mock_barslastcount.return_value = 10
        mock_mod.return_value = 1
        
        result = sqjz_signal(9, self.C)
        expected = {
            'B1': True, 'B2': False, 'B8': False, 'B9': True,
            'S1': False, 'S2': False, 'S8': False, 'S9': False
        }
        self.assertEqual(result, expected)

    @patch('sqjz.REF')
    @patch('sqjz.REFXV')
    @patch('sqjz.COUNT')
    @patch('sqjz.BARSL22STCOUNT')
    @patch('sqjz.MOD')
    def test_sqjq_all_sell_signals(self, mock_mod, mock_barslastcount, mock_count, mock_refxv, mock_ref):
        mock_ref.side_effect = lambda data, periods: [d + periods for d in data]
        mock_refxv.side_effect = lambda count, x: count
        mock_count.return_value = 9
        mock_barslastcount.return_value = 10
        mock_mod.return_value = 1

        result = sqjz_signal(9, self.C)
        expected = {
            'B1': False, 'B2': False, 'B8': False, 'B9': False,
            'S1': True, 'S2': False, 'S8': False, 'S9': True
        }
        self.assertEqual(result, expected)

    @patch('sqjz.REF')
    @patch('sqjz.REFXV')
    @patch('sqjz.COUNT')
    @patch('sqjz.BARSLASTCOUNT')
    @patch('sqjz.MOD')
    def test_sqjq_no_signals(self, mock_mod, mock_barslastcount, mock_count, mock_refxv, mock_ref):
        mock_ref.side_effect = lambda data, periods: data
        mock_refxv.side_effect = lambda count, x: count
        mock_count.return_value = 0
        mock_barslastcount.return_value = 0
        mock_mod.return_value = 1

        result = sqjz_signal(1, self.C)
        expected = {
            'B1': False, 'B2': False, 'B8': False, 'B9': False,
            'S1': False, 'S2': False, 'S8': False, 'S9': False
        }
        self.assertEqual(result, expected)

    @patch('sqjz.REF')
    @patch('sqjz.REFXV')
    @patch('sqjz.COUNT')
    @patch('sqjz.BARSLASTCOUNT')
    @patch('sqjz.MOD')
    def test_sqjq_edge_cases(self, mock_mod, mock_barslastcount, mock_count, mock_refxv, mock_ref):
        mock_ref.side_effect = lambda data, periods: data[-periods:] + data[:-periods]
        mock_refxv.side_effect = lambda count, x: count if x < len(data) else 0
        mock_count.return_value = 9
        mock_barslastcount.return_value = 10
        mock_mod.side_effect = lambda x, y: x % y

        result = sqjz_signal(2, self.C)
        expected = {
            'B1': False, 'B2': False, 'B8': False, 'B9': False,
            'S1': False, 'S2': False, 'S8': False, 'S9': False
        }
        self.assertEqual(result, expected)


if __name__ == '__main__':
    unittest.main()